<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class CaiguanController extends Controller
{
    //
    public function meallist(Request $req, $sid){
    	$stores = DB::table('stores')->where('sid',$sid)->first();
    	$category = DB::table('category')->where('sid',$sid)->get();
    	$meals = DB::table('meals')->where('sid',$sid)->get();

    	$mlist = DB::table('stores')
    		   ->join('category','stores.sid','=','category.sid')
    		   ->join('meals','category.lid','=','meals.parent_id')
    		   ->select('stores.*','category.*','meals.*')
    		   ->get();

        $zynum = 0;

    	for($i=0;$i<count($mlist);$i++){
            if($sid == $mlist[$i]->sid){
                $zynum += $mlist[$i]->ynum;
            }    		    		
    	}
    	//return $zynum;       

    	//dd($mlist);
    	return view('area.caiguan',[
            'stores'    =>  $stores,
    		'category' 	=> 	$category,
    		'meals' 	=> 	$meals,
    		'mlist' 	=> 	$mlist,
    		'zynum' 	=> 	$zynum
    	]);
    }
}
